#include <bits/stdc++.h>
using namespace std ;
const int MAXN = 3e3 + 10 ;
int t , n , m , l , v , slen ;
int cv [MAXN] , topo [MAXN];
bool b [MAXN] , allac , b1 [MAXN] ;
vector <int > s , s1 , ck [MAXN] ;
struct Nod
{
    int vl ;
    int vr ;
    int num ;
};
Nod cr [MAXN] ;
bool cmp_Nod (Nod a , Nod b)
{
    return a.vl < b.vl ;
}
void re_set ()
{
    memset (b , false , sizeof (b)) ;
    memset (b1 , false , sizeof (b1)) ;
    allac = false ;
    memset (topo , 0 , sizeof (topo)) ;
    s.clear () ;
    s1.clear () ;
    for (int i = 1;i <= m;++ i)
    {
        ck[i].clear () ;
    }
}
double func (int v1 , int v0 , int a)
{
    return (double) ( ( (v1 * v1) - (v0 * v0) ) / (2 * a) ) ;
}
bool check (int x)
{
    int len = ck[x].size () ;

    for (int i = 0;i < len;++ i)
        if (topo[ck[x][i]] == 1) return false ;

    for (int i = 0;i < len;++ i)
        topo[ck[x][i]] -- ;

    return true ;
}
void go_back (int x)
{
    int len = ck[x].size () ;

    for (int i = 0;i < len;++ i)
        topo[ck[x][i]] ++ ;
}
void get_info (int x , int a , int b , int c)
{
    int len = 0 ;
    cr[x].num = x ;
    if (b > v && c >= 0) cr[x].vl = a , cr[x].vr = l + 1 ;
    else if (b <= v && c <= 0) cr[x].vl = cr[x].vr = -1 ;
    else if (c > 0)
    {
        len = (int) ceil (func (v , b , c)) ;
        if (a + len > l) cr[x].vl = -1 , cr[x].vr = -1 ;
        else cr[x].vl = a + len , cr[x].vr = l + 1 ;
    }
    else
    {
        len = (int) ceil (func (v , b , c)) ;
        cr[x].vl = a ;
        if (a + len > l) cr[x].vr = l + 1 ;
        else cr[x].vr = a + len ;
    }
    if (cr[x].vl == -1 && cr[x].vr == -1) b1[x] = true ; ;
}
int solve1 ()
{
    sort (cv + 1 , cv + m + 1) ;
    sort (cr + 1 , cr + n + 1  , cmp_Nod) ;
    int res = 0 ;
    int mem = 0 ;
    for (int i = 1;i <= n;++ i)
    {
        int nnm = cr[i].num ;
        if (b1[nnm] == true) continue ;
        while (cv[mem] < cr[i].vl)
            mem ++ ;
        int j = mem ;
        while (cv[j] < cr[i].vr && j <= m)
            ck[j].push_back (nnm) , topo[nnm] ++ , j ++ ;
        if (j == mem + 1) b [mem] = true ;
        if (j != mem) res ++ ;
    }
    return res ;
}
int solve2 (int i)
{
    int res = 0 ;
    if (i == m + 1)
    {
        allac = true ;
        return 0 ;
    }
    if (b[i] == true)
        res = solve2 (i + 1) ;
    else
    {
        if (check (i) == true)
        {
            res = solve2 (i + 1) + 1 ;
            go_back (i) ;
        }
        if (allac == true) return res ;
        res = solve2 (i + 1) ;
    }
    return res ;
}
int main ()
{
    freopen ("detect.in" , "r" , stdin) ;
    freopen ("detect.out" , "w" , stdout) ;
    ios::sync_with_stdio(false) ;
    cin.tie() ; cout.tie() ;
    cin >> t ;
    for (int i = 1;i <= t;++ i)
    {
        re_set() ;
        cin >> n >> m >> l >> v ;
        for (int j = 1;j <= n;++ j)
        {
            int pi , vi , ai ;
            cin >> pi >> vi >> ai ;
            get_info(j , pi , vi , ai) ;
            //cout << j << ' ' << cr[j].vl << ' ' << cr[j].vr << endl ;
        }
        for (int j = 1;j <= m;++ j)
        {
            cin >> cv[j] ;
        }
        //cout << 1 << endl ;
        cout << solve1 () << ' ' ;
        //cout << 1 << endl ;
        cout << solve2 (1) << endl ;
    }
    return 0 ;
}
